package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;

@Setter
@Getter
@JsonIgnoreProperties({"handler,json,StateName"})
public class News extends BaseDomain {
    public static final int STATE_HOT = 0;//推荐
    public static final int STATE_NORMAL = 1;//普通
    //标题
    private String title;
    //副标题
    private String subtitle;
    //封面
    private String coverUrl;
    //推荐时间
    @JsonFormat(pattern = "y-M-d", timezone = "GMT+8")
    @DateTimeFormat(pattern = "y-M-d")
    private Date commendTime;
    //状态
    private Integer state;
    //分类
    private NewsCatalog catalog;
    //日报详情内容
    private NewsContent newsContent;
    //日报收藏次数
    private Integer collectCount;


    public String getJson() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("title", title);
        map.put("subtitle", subtitle);
        map.put("coverUrl", coverUrl);
        return JSONUtil.toJSONString(map);
    }

    public String getStateName() {
        if (this.state != null) {
            if (this.state == STATE_HOT) {
                return "推荐";
            }
            return "普通";
        }
        return "普通";
    }

}